import IWebSocket from "./IWebSocket";
import WebSocket from "./WebSocket";

export default class SocketInstance implements IWebSocket {
    
    private socket:WebSocket
    private static _instance:SocketInstance=new SocketInstance()

    constructor() 
    { 
        this.socket=new WebSocket()
    }
    //单例模式
    public static get instance()
    {
        if(!this._instance)
        {
            this._instance=new SocketInstance()
        }
        return this._instance
    }
    
    sendRequest(requestCode:any,actionCode:any,data:any)
    {
        //1.打包消息
        let msg=this.socket.packData(requestCode,actionCode,data)
        //2.发送消息
        this.socket.sendMsg(msg)
    }

}